/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is Forte for Java, Community Edition. The Initial
* Developer of the Original Code is Sun Microsystems, Inc. Portions
* Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.search;
import java.util.*;
import javax.swing.event.*;
import org.openide.windows.*;
import org.openide.nodes.*;
import org.openidex.search.*;
import org.netbeans.modules.search.res.*;
/**
* Button panel for result view.
*
* @author Petr Kuzel
* @version
*/
public class ResultViewPanel extends javax.swing.JPanel implements ChangeListener {
private ResultModel model;
/** Creates new form ResultViewPanel */
public ResultViewPanel(ResultModel model) {
setModel(model);
initComponents ();
initButtons();
}
public void setModel(ResultModel model) {
this.model = model;
model.addChangeListener (this);
}
/** initialize button "Use output window"*/
private void initButtons() {
outputButton.setVisible(model.canFillOutput());
stopButton.setEnabled(true);
}
/** Show search details in list.
*/
public void showDetail(DetailCookie detail) {
Vector data = new Vector(3);
if (detail != null) {
Enumeration en = detail.detail();
while (en.hasMoreElements()) {
Object next = en.nextElement();
if (next instanceof String) data.add(next);
}
}
detailList.setListData(data);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/
private void initComponents () {//GEN-BEGIN:initComponents
stopButton = new javax.swing.JButton ();
customizeButton = new javax.swing.JButton ();
outputButton = new javax.swing.JButton ();
detailList = new javax.swing.JList ();
closeButton = new javax.swing.JButton ();
setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints1;
stopButton.setIcon (Res.icon("STOP"));
stopButton.setText (Res.text("BUTTON_STOP"));
stopButton.setActionCommand ("stop");
stopButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
stopButtonActionPerformed (evt);
}
}
);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridwidth = 0;
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints1.insets = new java.awt.Insets (4, 4, 4, 4);
add (stopButton, gridBagConstraints1);
customizeButton.setText (Res.text("BUTTON_CUSTOMIZE"));
customizeButton.setActionCommand ("customize");
customizeButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
customizeButtonActionPerformed (evt);
}
}
);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridwidth = 0;
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints1.insets = new java.awt.Insets (4, 4, 4, 4);
add (customizeButton, gridBagConstraints1);
outputButton.setText (Res.text("BUTTON_FILL"));
outputButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
outputButtonActionPerformed (evt);
}
}
);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridwidth = 0;
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints1.insets = new java.awt.Insets (4, 4, 4, 4);
add (outputButton, gridBagConstraints1);
detailList.setBackground (new java.awt.Color (204, 204, 204));
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridwidth = 0;
gridBagConstraints1.weighty = 1.0;
add (detailList, gridBagConstraints1);
closeButton.setText (Res.text("BUTTON_CLOSE"));
closeButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
closeButtonActionPerformed (evt);
}
}
);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridwidth = 0;
gridBagConstraints1.gridheight = 0;
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints1.insets = new java.awt.Insets (4, 4, 4, 4);
gridBagConstraints1.anchor = java.awt.GridBagConstraints.SOUTH;
add (closeButton, gridBagConstraints1);
}//GEN-END:initComponents
private void outputButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_outputButtonActionPerformed
model.fillOutput(true);
}//GEN-LAST:event_outputButtonActionPerformed
private void outputCheckboxItemStateChanged (java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputCheckboxItemStateChanged
}//GEN-LAST:event_outputCheckboxItemStateChanged
private void closeButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
// close the component i am in
TopComponent.getRegistry().getActivated().close();
}//GEN-LAST:event_closeButtonActionPerformed
private void customizeButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customizeButtonActionPerformed
// open new Criteria view with itself as target
CriteriaModel criteria = model.getCriteriaModel();
//combo box hack in PresetView
criteria.setInitialized(false);
CriteriaView dialog = new CriteriaView(criteria);
criteria.setInitialized(true);
dialog.show();
// if ok (==search) open ResultView
if (dialog.getReturnStatus() == dialog.RET_OK) {
//stop previous search
model.stop();
// start new search
ResultModel result = performSearch(criteria.getNodes(), criteria);
// I do not have reference to my parent view,obrain it and set
ResultViewTopComponent view = (ResultViewTopComponent) TopComponent.getRegistry().getActivated();
view.setModel(result);
initButtons();
}
}//GEN-LAST:event_customizeButtonActionPerformed
/** start new search session. */
private ResultModel performSearch(Node[] nodes, CriteriaModel criteria) {
SearchEngine engine = new SearchEngineImpl();
ResultModel target = new ResultModel(criteria);
SearchTask task = engine.search(nodes, criteria.getCustomizedCriteria(), target);
target.setTask(task);
return target;
}
private void stopButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed
model.stop();
}//GEN-LAST:event_stopButtonActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton stopButton;
private javax.swing.JButton customizeButton;
private javax.swing.JButton outputButton;
private javax.swing.JList detailList;
private javax.swing.JButton closeButton;
// End of variables declaration//GEN-END:variables
/** Listen on model.
*/
public void stateChanged(final javax.swing.event.ChangeEvent event) {
if ( event.getSource() == model ) {
if (model.isDone()) {
stopButton.setEnabled(false);
}
}
}
}
/*
* Log
* 10 Gandalf-post-FCS1.6.2.2 4/4/00 Petr Kuzel Comments + output window
* fix
* 9 Gandalf-post-FCS1.6.2.1 3/9/00 Petr Kuzel I18N
* 8 Gandalf-post-FCS1.6.2.0 2/24/00 Ian Formanek Post FCS changes
* 7 Gandalf 1.6 1/13/00 Radko Najman I18N
* 6 Gandalf 1.5 1/11/00 Petr Kuzel Result details added.
* 5 Gandalf 1.4 1/5/00 Petr Kuzel Margins used. Help
* contexts.
* 4 Gandalf 1.3 1/4/00 Petr Kuzel Bug hunting.
* 3 Gandalf 1.2 12/23/99 Petr Kuzel Architecture improved.
* 2 Gandalf 1.1 12/17/99 Petr Kuzel Bundling.
* 1 Gandalf 1.0 12/16/99 Petr Kuzel
* $
*/